package com.stores.unitTests;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.stores.v1.toolset.Database;
import com.stores.v1.toolset.DatabaseInitializationException;

public class LocalDatabase extends Database {

	/**
	 * @throws SQLException
	 * 
	 */
	public LocalDatabase() {
		this.setDriver("com.mysql.jdbc.Driver");
		this.setConnectionString("jdbc:mysql://localhost:3306/ionlinestores");
		this.setUsername("root");
		this.setPassword("London99");
	}

	@Override
	public Connection getOpenConnection()
			throws DatabaseInitializationException {
		try {
			DriverManager.registerDriver((Driver) Class.forName(
					this.getDriver()).newInstance());
			return DriverManager.getConnection(this.getConnectionString(),
					this.getUsername(), this.getPassword());
		} catch (Exception e) {
			throw new DatabaseInitializationException(
					"Failed to initialize the database connection");
		}
	}
}
